//
//  ServerDetailVC.m
//  LazyHome
//
//  Created by yh on 2018/5/14.
//  Copyright © 2018年 yh. All rights reserved.
//

#import "ServerDetailVC.h"
#import "LHServerManager.h"

@interface ServerDetailVC ()

@property (weak, nonatomic) IBOutlet UITextField *nameLb;

@property (weak, nonatomic) IBOutlet UITextField *hostLb;

@property (weak, nonatomic) IBOutlet UITextField *portLb;


@end

@implementation ServerDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.nameLb.text = self.serverModel.serverName;
    self.hostLb.text = self.serverModel.host;
    self.portLb.text = self.serverModel.port;
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done)];
    self.navigationItem.rightBarButtonItem = item;
    
    
}
- (IBAction)selectServer:(id)sender {
    self.serverModel.serverName = self.nameLb.text;
    self.serverModel.host = self.hostLb.text;
    self.serverModel.port = self.portLb.text;
    [[LHServerManager manager] changeCurrentServerModelTo:self.serverModel];
    [self done];
}

- (void)done{
    self.serverModel.serverName = self.nameLb.text;
    self.serverModel.host = self.hostLb.text;
    self.serverModel.port = self.portLb.text;
    if (self.callBack) {
        self.callBack(self.serverModel, self.serverDetailMode);
    }
    [self.navigationController popViewControllerAnimated:YES];
}

- (ServerModel *)serverModel{
    if (!_serverModel) {
        _serverModel = [[ServerModel alloc] init];
    }
    return _serverModel;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
